import { CONSOLE_FONT_CORLOR, CONSOLE_BACKGROUND_CORLOR } from './libs/index';

export enum LOG_TEXT_START {
    INFO = '[INFO]',
    WARN = '[WARN]',
    ERROR = '[ERROR]',
    FATAL = '[FATAL]',
    DEBUG = '[DEBUG]',
}

export const log = {
    log(msg: string | ((typeMsg: string) => string), style: Array<CONSOLE_FONT_CORLOR | CONSOLE_BACKGROUND_CORLOR> | CONSOLE_FONT_CORLOR | CONSOLE_BACKGROUND_CORLOR = CONSOLE_FONT_CORLOR.green){
        // console.log(style+msg);
        let typeMsg = '';
        if(typeof style === 'string'){
            typeMsg = style;
        }
        if(Array.isArray(style)){
            style.forEach(type => {
                typeMsg += type;
            });
        }
        if(typeof msg === 'function'){
           return console.log(msg(typeMsg));
        }
        console.log(typeMsg+msg)
    },
    info(msg: string){
        this.log(`${LOG_TEXT_START.INFO} ${new Date()} ${msg}`, CONSOLE_FONT_CORLOR.green);
    },
    warn(msg: string){
        this.log(`${LOG_TEXT_START.WARN} ${new Date()} ${msg}`, CONSOLE_FONT_CORLOR.yellow);
    },
    error(msg: string){
        this.log(`${LOG_TEXT_START.ERROR} ${new Date()} ${msg}`, CONSOLE_FONT_CORLOR.red);
    },
    fatal(msg: string){
        this.log(`${LOG_TEXT_START.FATAL} ${new Date()} ${msg}`, [CONSOLE_FONT_CORLOR.underline, CONSOLE_FONT_CORLOR.magenta]);
    },
    debug(msg: string){
        this.log(`${LOG_TEXT_START.DEBUG} ${new Date()} ${msg}`, CONSOLE_FONT_CORLOR.blue);
    }
}